package com.jonas.sparkwork.answer2

import org.apache.hadoop.fs.{FileStatus, FileSystem, Path}

/**
 * @author Jonas Gao
 * @since 2022/4/17
 */
object FileLister {

  def listAll(fileSystem: FileSystem, f: Path): Array[FileStatus] = {
    val current = fileSystem.listStatus(f)
    current.filter(_.isDirectory).map(d => listAll(fileSystem, d.getPath)).filter(_.nonEmpty).foldLeft(current)(_ ++ _)
  }

}
